﻿Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.Edu.Ghi
Imports Gadgeteer.Modules.GHIElectronics



Namespace VBStopWatch
    Partial Public Class Program

        Dim timerOn As Boolean = False
        Dim counter As Integer = 0
        Dim seconds As Integer = 0
        Dim font As Font = Resources.GetFont(Resources.FontResources.small)
        Dim font2 As Font = Resources.GetFont(Resources.FontResources.NinaB)
        Dim WithEvents timer As GT.Timer = New GT.Timer(1000)  ' every 1 seconds



        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()
            '*******************************************************************************************
            ' Hardware modules added in the Program.gadgeteer designer view are used by typing 
            ' their name followed by a period, e.g.  button.  or  camera.
            '
            ' Many hardware modules generate useful events. To set up actions for those events, use the 
            ' left dropdown box at the top of this code editing window to choose a hardware module, then
            ' use the right dropdown box to choose the event - an event handler will be auto-generated.
            '*******************************************************************************************/

            ' Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started")

            display.SimpleGraphics.DisplayText("Stop Watch", font2, GT.Color.Cyan, 20, 20)
            displaySeconds()
            display.SimpleGraphics.DisplayText("LEFT button to Stop/Start", font, GT.Color.Cyan, 0, 90)
            display.SimpleGraphics.DisplayText("RIGHT button to Reset", font, GT.Color.Cyan, 0, 105)


        End Sub

        Private Sub displaySeconds()
            display.SimpleGraphics.DisplayRectangle(GT.Color.Cyan, 1, GT.Color.Black, 40, 40, 40, 40)
            display.SimpleGraphics.DisplayText((seconds \ 60).ToString() + " M", font2, GT.Color.White, 45, 45) 'Min using \ will return only the Quotient
            display.SimpleGraphics.DisplayText((seconds Mod 60).ToString() + " S", font2, GT.Color.White, 45, 60) 'sec is remainder after division by multiples of 60

        End Sub

        ' If you want to do something periodically, declare a GT.Timer by uncommenting the below line
        '   and then use the dropdown boxes at the top of this window to generate a Tick event handler.
        ' Dim WithEvents timer As GT.Timer = new GT.Timer(1000)  ' every second (1000ms)

        Private Sub timer_Tick(timer As Gadgeteer.Timer) Handles timer.Tick
            'If seconds >= 60 Then
            'seconds = 0
            'End If
            seconds = seconds + 1
            displaySeconds()

        End Sub

        Private Sub button_ButtonPressed(sender As Button, buttonState As Button.ButtonState) Handles button.ButtonPressed
            If timer.IsRunning Then
                timer.Stop()
            Else
                timer.Start()
            End If


        End Sub

        Private Sub button2_ButtonPressed(sender As Button, buttonState As Button.ButtonState) Handles button2.ButtonPressed
            'check to see if the timer is running and stop it.
            If timer.IsRunning Then
                timer.Stop()
            End If
            seconds = 0 'Reset back to 0
            displaySeconds()

        End Sub
    End Class
End Namespace